{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "provenance": []
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    },
    "language_info": {
      "name": "python"
    }
  },
  "cells": [
    {
      "cell_type": "markdown",
      "source": [
        "# **amk-tools**\n",
        "## Visualization of reaction networks created with AutoMeKin\n",
        "\n"
      ],
      "metadata": {
        "id": "vXtSvTouM1dG"
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "# Installing amk_tools"
      ],
      "metadata": {
        "id": "9LmhQ0GeMi9z"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "%%capture\n",
        "!apt update\n",
        "!git clone https://github.com/dgarayr/amk_tools.git\n",
        "%cd /content/amk_tools\n",
        "!pip install -e .\n",
        "%env PATH=\".:/content/amk_tools/scripts:/opt/bin:/usr/local/nvidia/bin:/usr/local/cuda/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/tools/node/bin:/tools/google-cloud-sdk/bin\""
      ],
      "metadata": {
        "id": "cQDTrDFQGe3p"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "source": [
        "### Upload a zip file with the finaldir folder of AutoMeKin.\n",
        "\n",
        "#### You must type the name of the file without the extension:\n",
        "#### **Example:**\n",
        "**You can upload a file named `FINAL_HL_FA.zip`**\n",
        "\n",
        "**and you should type: `FINAL_HL_FA`**"
      ],
      "metadata": {
        "id": "GfGgxYkkbGj_"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "%%capture\n",
        "%cd /content\n",
        "zipfile = input('Name of the zip file (without the extension): ')\n",
        "!unzip {zipfile}.zip"
      ],
      "metadata": {
        "id": "zd7yX4CkbQeg"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "source": [
        "*Generate network.html for visualization*\n",
        "\n",
        "*The third line should be changed according to your needs*"
      ],
      "metadata": {
        "id": "fX1nuW9k13DS"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "from os import path\n",
        "%cd /content/\n",
        "!amk_gen_view.py {zipfile} RXNet.cg --paths\n",
        "!rm -rf HTML\n",
        "!mkdir HTML\n",
        "!mv network.html HTML\n",
        "%cd /content/HTML"
      ],
      "metadata": {
        "id": "pTH02rKqmGSm"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "# @title ##### _Open the file network.html_\n",
        "import IPython\n",
        "from IPython.core.magic import register_line_magic\n",
        "import subprocess\n",
        "\n",
        "@register_line_magic\n",
        "def run_local_server(line):\n",
        "    handle = IPython.display.display(\n",
        "            IPython.display.Pretty(\"Launching my server...\"),\n",
        "            display_id=True,\n",
        "    )\n",
        "    subprocess.Popen(['python', '-m', 'http.server'])\n",
        "    shell = \"\"\"\n",
        "        (async () => {\n",
        "            const url = new URL(await google.colab.kernel.proxyPort(8000, {'cache': true}));\n",
        "            const iframe = document.createElement('iframe');\n",
        "            iframe.src = url;\n",
        "            iframe.setAttribute('width', '100%');\n",
        "            iframe.setAttribute('height', '800');\n",
        "            iframe.setAttribute('frameborder', 0);\n",
        "            document.body.appendChild(iframe);\n",
        "        })();\n",
        "    \"\"\"\n",
        "    script = IPython.display.Javascript(shell)\n",
        "    handle.update(script)\n",
        "!fuser -k 8000/tcp\n",
        "%run_local_server"
      ],
      "metadata": {
        "cellView": "form",
        "id": "Hk9n87rhkXZJ"
      },
      "execution_count": null,
      "outputs": []
    }
  ]
}